#pragma once
#include "Renderer.h"
#include "LightActor.h"

namespace mini
{
	class CDeferredRenderer : public CRenderer
	{
		enum GBufferType
		{
			G_COLOR,
			G_NORMAL,
			G_POSITION,
		};

		friend class CRendererFactory;
		friend class CRendererEngine;
	private:
		CDeferredRenderer(CDevice* pDevice);
		bool initialise();
		virtual void addUnit(CUnit* pUnit, CMaterialUnit* pMaterialUnit, EntityType Type, INT32 zLayer);
		virtual void commitToGpu();
		void drawUnit(DeviceContext* pContext, CShaderUnit* pShaderUnit);
		void drawLightEffect(DeviceContext* pContext, CShaderUnit* pShaderUnit);

	public:
		virtual ~CDeferredRenderer();
	
	private:
		static const int BUFFER_COUNT = 3;
		CMatrix mOrthoMatrix;
		CMeshUnit*	mpMeshUnit = nullptr;
		CMaterialUnit* mpMaterialUnit = nullptr;
		std::vector<CTexture*> mRenderTextureArray;
		std::function<void(DeviceContext*, CShaderUnit*)> mDrawFuns[2];
		ID3D11RenderTargetView* mpRenderTargetViewArray[BUFFER_COUNT];
		ID3D11Texture2D* mpDepthStencilBuffer = nullptr;
		ID3D11DepthStencilView* mpDepthStencilView = nullptr;
		std::vector<LightColor>	mLights;
		std::vector<float>	mLightsAngle;
	};
}
